package org.xq.mq.component;

import org.xq.mq.model.RedisQueueMessage;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisQueueProducer {
    @Autowired
    RedisTemplate redisTemplate;

    /**
     * 发送消息
     *
     * @param queueName         队列名称
     * @param redisQueueMessage 消息
     */
    public void sendMessage(String queueName, RedisQueueMessage redisQueueMessage) {
        redisTemplate.boundListOps("queue:" + queueName).leftPush(JSON.toJSONString(redisQueueMessage));
        System.out.println("消息发送成功: queue_name=[" + queueName + "] " + redisQueueMessage.getContent());
    }
}
